from utils.misc.functional import cacheable
from log import Log

gLogInstaller = None

__all__ = [
    'gLogInstaller'
]

class LogInstaller:
    applications = {} # {application -> Log}

    @staticmethod
    @cacheable
    def install(application, logWarn=True, logInfo=False, logDebug=False):
        log = LogInstaller.applications.get(application, None)
        if log is None:
            log = Log(application)
        enabledLogLevels = [
            'WARN' if logWarn else None,
            'INFO' if logInfo else None,
            'DEBUG' if logDebug else None
        ]
        disabledLevels = [
            'WARN' if not logWarn else None,
            'INFO' if not logInfo else None,
            'DEBUG' if not logDebug else None
        ]
        log.enableLevels(*enabledLogLevels)
        log.disableLevels(*disabledLevels)
        LogInstaller.applications.setdefault(application, log)
        return log

    def uninstall(self, application):
        pass

if gLogInstaller is None:
    gLogInstaller = LogInstaller()


